//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _MODEL_RANDOMDOUBLE_H
#define _MODEL_RANDOMDOUBLE_H
//
#include <global.h>
#include <common/range_fwd.h>
#include "multitypedata.h"
#include "multitypedatacontainer.h"
//
namespace model
{
class RandomDouble:public MultiTypeDataContainer
{
//data classes
public:
   static int const type_constant=1;
   static int const type_interval=2;
   class Data:public MultiTypeData
   {
      Q_DISABLE_COPY(Data)
      DISABLE_ADDRESSOF(Data)
   protected:
      Data(int p_type);
   public:
      virtual double calculate(double p_phase=0.5)const=0;
      virtual Range get_range()const=0;
   };
   class Constant:public Data
   {
      Q_DISABLE_COPY(Constant)
      DISABLE_ADDRESSOF(Constant)
   public:
      Constant(double p_value=0.0);
      double get_value()const;
      void set_value(double p_value);
      double calculate(double p_phase=0.5)const;
      Range get_range()const;
   public:
      MultiTypeData *clone()const;
      void store(QDataStream &p_stream)const;
      void restore(QDataStream &p_stream);
   private:
      double value;
   };
   class Interval:public Data
   {
      Q_DISABLE_COPY(Interval)
      DISABLE_ADDRESSOF(Interval)
   public:
      Interval(double p_min=0.0,double p_max=0.0);
      double get_min()const;
      void set_min(double p_min);
      double get_max()const;
      void set_max(double p_max);
      double calculate(double p_phase=0.5)const;
      Range get_range()const;
   public:
      MultiTypeData *clone()const;
      void store(QDataStream &p_stream)const;
      void restore(QDataStream &p_stream);
   private:
      double min,max;
   };
//construction
public:
   RandomDouble();
   RandomDouble(Data *p_data);
//data
public:
   const Data &data()const;
   const Constant &as_constant()const;
   Constant &as_constant();
   const Interval &as_interval()const;
   Interval &as_interval();
//type
protected:
   MultiTypeData *create_data(int p_type)const;
};
}
//
#endif
